<?php

include('../ZmopSdk.php');
include('./ZmopClient.php');
include('./request/ZhimaAuthInfoAuthorizeRequest.php');  

class TestZhimaAuthInfoAuthorize {
    //芝麻信用网关地址
    public $gatewayUrl = "https://zmopenapi.zmxy.com.cn/openapi.do";
    //商户私钥文件
    public $privateKeyFile = "./cert/rsa_private_key.pem";
    //芝麻公钥文件
    public $zmPublicKeyFile = "./cert/zima_public_key.pem";
    //数据编码格式
    public $charset = "UTF-8";
    //芝麻分配给商户的 appId
    public $appId = "1000791";
    
    public function testZhimaAuthInfoAuthorize(){
         $client = new ZmopClient($this->gatewayUrl,$this->appId,$this->charset,$this->privateKeyFile,$this->zmPublicKeyFile);
         $request = new ZhimaAuthInfoAuthorizeRequest();
         $request->setChannel("app");
         $request->setPlatform("zmop");
                $request->setIdentityType("2");// 必要参数         
                $request->setIdentityParam("{\"name\":\"李黄德\",\"certType\":\"IDENTITY_CARD\",\"certNo\":\"533523198005010019\"}");// 必要参数         
                $request->setBizParams("{\"auth_code\":\"M_H5\",\"channelType\":\"app\",\"state\":\"商户自定义\"}");// 
print_r($request);
                  $url = $client->generatePageRedirectInvokeUrl($request);
                  //echo $url;
          //echo json_encode($response);
    }
    public function testZhimaCreditScoreGet(){
        $client = new ZmopClient($this->gatewayUrl,$this->appId,$this->charset,$this->privateKeyFile,$this->zmPublicKeyFile);
        $request = new ZhimaCreditScoreGetRequest();
        $request->setChannel("apppc");
        $request->setPlatform("zmop");
        $request->setTransactionId("2016030312515880400000004651581");//必要参数，业务流水号
        $request->setProductCode("w1010100100000000001");//必要参数，这个值对于芝麻分产品是固定的，无需修改
        $request->setOpenId("268806303103918685035174450");//必要参数，授权获得的openid
        $response = $client->execute($request);
        echo json_encode($response);
    }
}
$zm = new TestZhimaAuthInfoAuthorize();
//$zm->testZhimaAuthInfoAuthorize();



/*
include('../ZmopSdk.php');
include('./ZmopClient.php');
include('./request/ZhimaAuthInfoAuthorizeRequest.php');
class TestAuthFreeze {
        //芝麻信用网关地址
        public $gatewayUrl = "https://zmopenapi.zmxy.com.cn/openapi.do";
        //商户公钥文件
        //芝麻公钥文件
        public $privateKeyFile = "cert/rsa_private_key.pem";
        public $zmPublicKeyFile = "cert/rsa_public_key.pem";

        //数据编码格式
        public $charset = "UTF-8";
        //芝麻分配给商户的appId
        public $appId = "1000791";


    //生成移动端SDK 集成需要的sign 参数 ，并进行urlEncode
    public function generateSign($certNo,$name,$certType='IDENTITY_CARD'){
        $client = new ZmopClient($this->gatewayUrl, $this->appId, $this->charset, $this->privateKeyFile,$this->zmPublicKeyFile);
 
        $request = new ZhimaAuthInfoAuthorizeRequest();
        $request->setScene("test");
        // 授权来源渠道设置为appsdk
        $request->setChannel("appsdk");
        // 授权类型设置为2标识为证件号授权见“章节4中的业务入参说明identity_type”
        $request->setIdentityType("2");
        // 构造授权业务入参证件号，姓名，证件类型;“章节4中的业务入参说明identity_param”
        $request->setIdentityParam("{\"certNo\":\"$certNo\",\"certType\":\"IDENTITY_CARD\", \"name\":\"$name\"}");
        // 构造业务入参扩展参数“章节4中的业务入参说明biz_params”
        $request->setBizParams("{\"auth_code\":\"M_APPSDK\"}");

        $params = $client->generateEncryptedParamWithUrlEncode($request);
        $sign = $client->generateSignWithUrlEncode($request);

        $data['gatewayUrl'] = $this->gatewayUrl;
        $data['appId'] = $this->appId;
        $data['charset'] = $this->charset;
        $data['params']=$params;
        $data['sign'] = $sign;
        return $data;
    }

    // 解密
    public function zhimacallback($params){
        $this->privateKeyFile= "cert/rsa_private_key.pem";
        $client = new ZmopClient($this->gatewayUrl, $this->appId, $this->charset, $this->privateKeyFile,$this->zmPublicKeyFile);
        $result=$client->generateSignCallBack($params,$this->privateKeyFile);
        return $result;
    }
} 
$zm = new TestAuthFreeze();
print_r($zm->generateSign('123','22222'));
//$zm->zhimacallback();

*/
